<?php
function getPosts($idusers=null){
	$posts = array();
	if($idusers != null){
		$r = mysql_query("SELECT title, username AS author, content, time, a.events_idevents FROM 
			(SELECT title, author, content, time, events_idevents FROM posts 
			INNER JOIN 
			(SELECT * FROM subscribers WHERE users_idusers='".$idusers."') AS sub 
			USING (events_idevents) 
			UNION 
			SELECT title, author, content, time, events_idevents FROM posts 
			WHERE events_idevents IS NULL) AS a 
			INNER JOIN users ON users.idusers = a.author"
		);
		while($row = mysql_fetch_assoc($r))
			array_push($posts, $row);
	}
	else{
		$r = mysql_query("SELECT title, username AS author, content, time, a.events_idevents FROM 
			(SELECT title, author, content, time, events_idevents FROM posts 
			WHERE events_idevents IS NULL) AS a INNER JOIN users ON users.idusers = a.author");
		while($row = mysql_fetch_assoc($r))
			array_push($posts, $row);
	}
	return $posts;
}

function getEvents(){
	$c = connect();
	$r = mysql_query("SELECT idevent, name, description, meetings_idmeetings FROM events");
	$events = array();
	while($row = mysql_fetch_assoc($r))
		array_push($events, $row);
	mysql_close($c);
	return $events;
}
?>
